package com.esm.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.esm.model.Walfare;
import com.esm.service.SelectWalfareService_zxk;
import com.esm.serviceimpl.SelectWalfareServiceImpl_zxk;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 
 * @author 康少
 *
 * 2017年1月9日
 */
public class GetWalfareController_zxk extends HttpServlet{
	SelectWalfareService_zxk walfares = new SelectWalfareServiceImpl_zxk();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String uname = req.getParameter("uname");
		List<Walfare> walfare = walfares.getWalfareByUname(uname);
		String[] array = new String[1024];
		JSONObject jo = new JSONObject();
		jo.clear();
		for (int i = 0; i < walfare.size(); i++) {
			array[i] = walfare.get(i).getWname();
		}
		for (int i = 0; i < walfare.size(); i++) {
			switch (array[i]) {
			case "养老保险":
				jo.put("yang", 1);break;
			case "医疗保险":
				jo.put("yi", 1);break;
			case "失业保险":
				jo.put("shi", 1);break;
			case "工伤保险":
				jo.put("gong", 1);break;
			case "生育保险":
				jo.put("sheng", 1);break;
			case "住房公积金":
				jo.put("zhu", 1);break;
			case "电话补贴":
				jo.put("dian", 1);break;
			case "餐饮补贴":
				jo.put("can", 1);break;
			case "交通补贴":
				jo.put("jiao", 1);
			break;
			}
		}
		PrintWriter pw = resp.getWriter();
		pw.write(jo.toString());
		pw.flush();
		pw.close();
	}
}
